﻿/*
-----------------------------------------------------------------------------
This source file is part of Cell Cloud.

Copyright (c) 2009-2012 Cell Cloud Team - cellcloudproject@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/

#ifndef CellInet6Address_h
#define CellInet6Address_h

#include "CellPrerequisites.h"
#include "CellInetAddress.h"

namespace cell
{
/** \addtogroup Core
 *  @{
 */
/** \addtogroup General
 *  @{
 */

/** 此类表示互联网协议第 6 版 (IPv6) 地址。
@author
	Jiangwei Xu
*/
class _CellExport Inet6Address : public InetAddress, public GeneralAlloc
{
public:
	/** 默认构造函数。
	*/
	Inet6Address(void);

	/** 构造函数。
	*/
	explicit
	Inet6Address(const String& host);

	/** 构造函数。
	*/
	explicit
	Inet6Address(uint port);

	/** 构造函数。
	*/
	Inet6Address(const String& host, uint port);

	/** 构造函数。
	*/
	Inet6Address(const Inet6Address& other);

	/** 构造函数。
	*/
	Inet6Address(const InetAddress& other);

	/** 析构函数。
	*/
	virtual ~Inet6Address(void);

public:
	/** 赋值操作符。
	*/
	Inet6Address& operator=(const Inet6Address& other);

	/** 等于操作符，判断地址是否相同。
	*/
	bool operator==(const Inet6Address& other) const;
	bool operator==(Inet6Address& other) const;

	/** 等于操作符，判断地址是否相同。
	*/
	bool compare(const InetAddress& addr) const;
	bool compare(InetAddress& addr) const;

	/** 该地址是否有效。
	*/
	bool isValid(void) const;

	/** 该地址是否符合 IPv4 规范。
	*/
	bool isIPv4(void) const;

	/** 该地址是否符合 IPv6 规范。
	*/
	bool isIPv6(void) const;

public:
	/**
	*/
	void format(sockaddr_in6& addr);
};

/** IPv6 地址列表 */
typedef std::vector<Inet6Address> Inet6AddressList;

/** @} */
/** @} */
} // end namespace cell

#endif // CellInet6Address_h
